package de.gameduell.framework.queue {
	import de.gameduell.framework.asset.AssetEvent;
	import de.gameduell.framework.asset.IAsset;
	import de.gameduell.framework.queue.IGDAction;

	import flash.events.Event;
	import flash.events.EventDispatcher;

	/**
	 * @author ddoe
	 */
	public class AssetAction extends EventDispatcher implements IGDAction {
		private var asset:IAsset;
		private var actionQueue:GDActionQueue;
		private var _desciption:String;

		public function AssetAction(aAsset:IAsset,invokeNow:Boolean = false,aDescription:String = "AssetAction") {
			_desciption = aDescription;
			asset = aAsset;
			asset.addEventListener(AssetEvent.COMPLETE, onAssetComplete);
			actionQueue = GDActionQueue.getInstance();
			if(invokeNow){
				invoke();
			}		
		}

		public function compute():void {
			asset.load();
		}
		
		public function invoke():void {
			actionQueue.add(this);
		}
		
		private function onAssetComplete(event:Event):void{
			dispatchEvent(new ActionEvent(ActionEvent.DONE));
		}
		
		public function get description():String {		
			return _desciption;
		}
		

	}
}
